package com.hnevc.xiewenguang;

import java.io.File;
import java.io.FilenameFilter;

/**
 *
 * 遍历指定文件名后缀
 *
 */
public class Example06 {

    public static void main(String[] args) {
        File file = new File("C:\\Users\\Administrator\\IdeaProjects\\Demo01\\src\\com\\hnevc\\xiewenguang");
        //创建过滤器
        FilenameFilter filter = new FilenameFilter() {
            @Override
            public boolean accept(File dir, String name) {
                File currFile = new File(dir,name);
                if(currFile.isFile() && name.endsWith("docx")){
                    return true;
                }
                return false;
            }
        };
        if (file.exists()){
            String[] lists = file.list(filter);//为当前获取文件名列表进行筛选得到符合过滤器当中的条件
            for (String name:lists){
                System.out.println(name);
            }
        }
    }
}
